package com.lkd.controller;

import com.lkd.dto.UserPageDto;
import com.lkd.entity.Role;
import com.lkd.entity.User;
import com.lkd.result.PageBean;
import com.lkd.result.Result;
import com.lkd.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/user-service/user")
public class UserController {
    private final UserService userService;

    //人员搜索
    @GetMapping("/search")
    public Result search(UserPageDto userPageDto){
        PageBean pageBean= userService.search(userPageDto);
        return Result.success(pageBean);
    }

    //新增人员
    @PostMapping
    public Result save(@RequestBody User user){
        Boolean result = userService.save(user);
        return Result.success(result);
    }

    //修改人员
    @PutMapping
    public Result update(@RequestBody User user){
        Boolean result = userService.update(user);
        return Result.success(result);
    }
    //删除人员
    @DeleteMapping("/{userId}")
    public Result delete(@PathVariable("userId") Integer userId){
        Boolean result = userService.delete(userId);
        return Result.success(result);
    }

}
